<?php
namespace app\api\controller\v2;
use app\api\controller\Common;

class Message extends Common{
	var $modelDb;
	public function _initialize(){
		parent::_initialize();
		$this->modelDb = model("Message");
	}
	public function add(){
		if ($this->postData['receive_uid'] == $this->uinfo['id']) {
			return $this->app_error('不能给自己发私信');
		}
		$this->postData['send_uid'] = $this->uinfo['id'];
		$id = $this->modelDb->save_data($this->postData);
		if ($id) {
			return $this->app_success();
		}else{
			return $this->app_error($this->modelDb->getError());
		}
	}
    // 用户打开了站内信，将unread字段改为0
	public function read() {
		$count = model('AdminUser')->where('userid', $this->uinfo['userid'])->setField('unread', 0);
		return $this->app_success();
	}
}